'经验瓶掉落组件，负责经验瓶的掉落控制'

extends Node

@export_range(1,100) var drop_percent: int = 50#掉落百分比*100
@export var health_component: Node
@export var vial_scene: PackedScene

func _ready() -> void:
	(health_component as HealthComponent).died.connect(on_died)
	pass

#判断是否掉落
func on_died() -> void:
	if randi_range(1,100) > (drop_percent * (1 + .1 * GameSaves.get_upgrade_quantity("experience_gain"))):
		return
	if vial_scene == null:
		return
	if not owner is Node2D:
		return
	var spawn_position = (owner as Node2D).global_position
	var vial_instance = vial_scene.instantiate() as Node2D
	self.get_tree().get_first_node_in_group("entities_layer").add_child.call_deferred(vial_instance)
	vial_instance.global_position = spawn_position
	pass
